package com.minminaya.source;

import java.util.Stack;

public class Algorithm_5 {

    public static class MList<T> {
        private Stack<T> stack1 = new Stack<>();
        private Stack<T> stack2 = new Stack<>();

        public void appendTail(T t) {
            stack1.add(t);
        }

        public T deleteHead() {

            //判断边界
            if (stack2.isEmpty()) {
                while (!stack1.isEmpty()) {
                    stack2.add(stack1.pop());
                }
            }
            //无数据则排出异常
            if (stack2.isEmpty()) {
                throw new RuntimeException("no more element");
            }
            return stack2.pop();
        }

    }
}
